package de.edb.model;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


@Entity
@Table(name="tbl_event")
public class Event {
    @Id
    @GeneratedValue
	@Column(name="pk_event")
    private Integer id;
    private String name;
    private String description;
	private Date created;
    private Date begin;
    private Date end;
    private double price;
    private String ticketlink;
	@ManyToOne
	@JoinColumn(name = "fk_location", nullable = true)
	private Location location;
	@ManyToMany(targetEntity = de.edb.model.Artist.class,
			cascade={CascadeType.PERSIST},
			fetch = FetchType.EAGER)
	@JoinTable(
			name="tbl_artist_event",
			joinColumns={@JoinColumn(name="fk_event")},
			inverseJoinColumns={@JoinColumn(name="fk_artist")})
	private Set<Artist> artists;

	public Event(String name, String description, Date begin, Date end) {
		this.name = name;
		this.description = description;
		this.begin = begin;
		this.end = end;
	}
	
	public Event(String name, String description) {
		this.name = name;
		this.description = description;
	}
	
	public Event() {
		this.name = "TEST";
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public Set<Artist> getArtists() {
		return artists;
	}

	public void setArtists(Set<Artist> artists) {
		this.artists = artists;
	}
	
	public void setBegin(Date b){
		this.begin = b;
	}
	
	public Date getBegin(){
		return begin;
	}
	
	public void setEnd(Date e){
		this.end = e;
	}
	
	public Date getEnd(){
		return end;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	public String getName(){
		return name;
	}
	
	public void setDescription(String d){
		this.description = d;
	}
	
	public String getDescription(){
		return description;
	}
	
	public void setPrice(double p){
		this.price = p;
	}
	
	public double getPrice(){
		return price;
	}
	
	public String getBeginString(){
		SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
		return sdf.format(this.begin);
	}
	
	public String getEndString(){
		SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
		return sdf.format(this.end);
	}

	public String getTicketlink() {
		return ticketlink;
	}

	public void setTicketlink(String ticketlink) {
		this.ticketlink = ticketlink;
	}

}
